package com.tech.thread;

/**
 * @Description:
 * @Author: zl
 * @Date: 2019/7/12 14:52
 */
public class JoinTest {

    public static void main(String[] args) throws InterruptedException {
        Thread001 thread001 = new Thread001();
        Thread002 thread002 = new Thread002();
        Thread t01 = new Thread(thread001);
        Thread t02 = new Thread(thread002);

        //step.1  启动第一个
        t01.start();
        t02.start();
        t01.join();// 调用join方法后主线程等待 t01线程执行后在继续执行主线程
        System.out.println(" this is main");


    }
}

class Thread001 implements Runnable {

    @Override
    public void run() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("this is Thread-1");
    }
}

class Thread002 implements Runnable {

    @Override
    public void run() {
        System.out.println("this is Thread-2");
    }
}